package;

import board.Dice;
import board.Roulette;
import board.Team;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.input.gamepad.LogitechButtonID;
import flixel.input.gamepad.PS4ButtonID;
import flixel.util.FlxColor;
import haxe.Utf8;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;

/**
 * A FlxState which can be used for the actual gameplay.
 */
class LogoState extends FlxState
{
	var text1:FlxText;
	var text2:FlxText;
	var text3:FlxText;
	var start:FlxText;
	var logo:FlxSprite;
	var blinking:Bool;
	var time:Float;
	var reset:Float;
	/**
	 * Function that is called up when to state is created to set it up. 
	 */
	override public function create():Void
	{
		super.create();
		FlxG.mouse.visible = false;
		FlxG.camera.bgColor = FlxColor.BLACK;
		logo = new FlxSprite(0, 0);
		logo.loadGraphic("assets/images/logo.png");
		logo.x = FlxG.width / 2 - logo.width / 2;
		logo.y = FlxG.height / 2 - logo.height / 2;
		logo.alpha = 0;
		add(logo);
		time = 1;
		reset = 1000;
	}
	
	/**
	 * Function that is called when this state is destroyed - you might want to 
	 * consider setting all objects this state uses to null to help garbage collection.
	 */
	override public function destroy():Void
	{
		super.destroy();
	}

	/**
	 * Function that is called once every frame.
	 */
	override public function update():Void
	{
		super.update();
		time -= FlxG.elapsed;
		reset -= FlxG.elapsed;
		if (time < 0)
		{
			time = 1000;
			var tween = FlxTween.tween(logo,{alpha:1},1,{complete:tweenEnd});
		}
		if (reset < 0)
		{
			reset = 1000;
			var tween = FlxTween.tween(logo,{alpha:0},1,{complete:tweenEnd2});
		}
			
	}	
	
	private function tweenEnd(tween2:FlxTween):Void
	{
		reset = 2;
	}
	
	private function tweenEnd2(tween2:FlxTween):Void
	{
		FlxG.camera.fade(FlxColor.BLACK,1,false,onFade);
	}
	
	private function onFade():Void
	{
		FlxG.switchState(new IntroState());
	}
}